package com.ktjy.t382.ch02.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktjy.t382.ch02.entity.SysUser;
import com.ktjy.t382.ch02.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImp implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public Page<SysUser> selectList(SysUser sysUser, int current, int size) {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>(sysUser);
        if (sysUser.getAccount() != null && !"".equals(sysUser.getAccount())) {
            wrapper.eq("account", sysUser.getAccount());
        }
        Page<SysUser> page = new Page<>(current, size);
        return userMapper.selectPage(page, wrapper);
    }

    @Override
    public int add(SysUser sysUser) {
        return userMapper.insert(sysUser);
    }

    @Override
    public int update(SysUser sysUser) {
        return userMapper.updateById(sysUser);
    }

    @Override
    public SysUser getId(Integer id) {
        return userMapper.selectById(id);
    }
}
